package com.kelvin.paopao.module.main.date.publish.eat;

import com.hyphenate.easeui.utils.SpUtil;
import com.kelvin.kelvinlib.utils.ToastUtil;
import com.kelvin.paopao.api.RetrofitService;
import com.kelvin.paopao.api.responseBean.CommonListResponse;
import com.kelvin.paopao.utils.DialogMaker;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/5/14.
 */

public class PublishEatPresenter implements IPublishEatPresenter {

    private PublicEatActivity mView;

    public PublishEatPresenter(PublicEatActivity view) {
        this.mView = view;
    }

    @Override
    public void getData(boolean isRefresh) {

    }

    @Override
    public void getMoreData() {

    }


    @Override
    public void publishEat(String oAddress, String time, String osex, String opayMode,
                           String isTip, String tipPrice, String hours, String introduce,
                           String img1, String img2, String img3, String oAddressId, String oDate) {
        RetrofitService.publishDate("order_add", " ", oAddress, osex, opayMode, isTip, tipPrice
                , hours, "0", "0", introduce, "0", SpUtil.getLoginHuanxin_id(mView),
                img1, img2, img3, oAddressId, oDate).doOnSubscribe(new Consumer<Disposable>() {
            @Override
            public void accept(@NonNull Disposable disposable) throws Exception {
                DialogMaker.showProgressDialog(mView, "邀约发布中，请稍候~~");
            }
        }).subscribeOn(AndroidSchedulers.mainThread()).observeOn(AndroidSchedulers.mainThread()).
                subscribe(new Consumer<CommonListResponse>() {
                    @Override
                    public void accept(@NonNull CommonListResponse commonListResponse) throws Exception {
                        if (commonListResponse.getReason().equals("成功")) {
                            mView.finish();
                            ToastUtil.showToast(mView, "邀约发布成功");
                        }
                        DialogMaker.diamiss();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {
                        DialogMaker.diamiss();
                    }
                }, new Action() {
                    @Override
                    public void run() throws Exception {
                        DialogMaker.diamiss();
                    }
                });
    }
}
